<?php

require_once 'composer/vendor/propel/propel1/runtime/lib/Propel.php';
Propel::init("composer/vendor/propel/propel1/generator/bin/em/build/conf/esportsmaniacs-conf.php");
set_include_path("composer/vendor/propel/propel1/generator/bin/em/build/classes");
session_start();


$usuario = $_POST['usuario'];
$password = md5($_POST['password']);

$extra = 'index.php';

try {
    $user = usuariosQuery::create()
            ->filterByUsuario($usuario)
            ->findOne();

    if ($user != null) {
        if ($password == $user->getPassword() && $user->getVerificado()) {

            $_SESSION['user'] = $user;
            if ($_POST['recordar'] == true) {
                setcookie('user', $user->getId(), time() + 60 * 60 * 24 * 7);
            }
        } else {
            $_SESSION['UserIncorrecto'] = "<li class='li-error'>Usuario o Contraseña incorrecto</li>";
            $extra = 'login2.php';
        }
    } else {
        $_SESSION['UserIncorrecto'] = "<li class='li-error'>Usuario o Contraseña incorrecto</li>";
        $extra = 'login2.php';
        
    }
} catch (Exception $e) {
    $_SESSION['UserIncorrecto'] = "Error";
}

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

header("Location: http://" . $host . $uri . "/" . $extra);
die();
?>
